<!DOCTYPE html>
<html lang="en">  
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<title>提现</title>
</head>
<link rel="stylesheet" href="__CSS__/withdrawCash.min.css">
<body>
	<div id="app" v-cloak>
		<div class="bigMoney" v-if="userInfo.id!=undefined">
			¥ {{userInfo.money}}
		</div>
		<div class="yue">
			账户余额
		</div>
		<div class="withdrawCash">
			<span>奖励总额</span>
			<p><input type="number" v-model="price" @input="howMuch"> 元</p>
		</div>
		<div class="withdrawAll" @click="getAll">
			全部提现
		</div>

		<div class="ok" @click="submit">
			确认提现
		</div>
		<div class="toSend" @click="toSend">
			去发红包
		</div>
		<div class="clear" v-if="flag">
			{{text}}
		</div>
	</div>
	<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
	<script src="__JS__/vue.min.js"></script>
	<script src="__JS__/common.min.js"></script>
	<script>
		var app = new Vue({
			el: "#app",
			data: {
				wxdata: '',      //微信信息
				price: '',    	 //提现金额
				flag: false,    //提示
				userInfo: '',
				text: '',  //提示内容
			},
			computed: {
				 
			},
			mounted: function() {
				var url = location.href;
				var that = this;
				$.ajax({
					url: '{:U('setting/wxJsSDK')}',
					type: 'post',
					data: {
						url: url,
						code: 1
					},
					success: function(data) {
						if (data.code != 200) {
							alert(data.msg);
							return false;
						}
						that.wxdata = data.data;
						wx.config({
						    debug: false, 
						    appId: that.wxdata.appId, 
						    timestamp: that.wxdata.timestamp, 
						    nonceStr: that.wxdata.nonceStr, 
						    signature: that.wxdata.signature,
						    jsApiList: [
						    	"onMenuShareTimeline",   //分享到朋友圈
								"onMenuShareAppMessage",  //分享给朋友
						    ] 
						});
						var url2 = url.split('withdrawCash').join('sendPackage')
						wx.ready(function(){
							$.ajax({
								url: '{:U('user/info')}',
								type: 'post',
								data: {},
								success: function(data) {
									if (data.code == 200) {
										that.userInfo = data.data;
									} else {
										alert(data.msg);
										return false;
									}
								},
								error: function() {

								}
							})
							wx.onMenuShareAppMessage({
							    title: '口令红包等你来抢', 
							    desc: '口令红包 说对算你赢', 
							    link: url2, 
							    imgUrl: 'http://sfmhb.shanfengmao.com/logo.png', 
							    type: '', 
							    dataUrl: '', 
							    success: function () { 
									that.text = '分享成功';
									that.flag = true;
						    		setTimeout(function() {
						    			that.flag = false;
						    		},1500)
							    },
							    cancel: function () { 
							        
							    }
							});
							wx.onMenuShareTimeline({
							    title: '口令红包等你来抢', 
							    link: url2, 
							    imgUrl: 'http://sfmhb.shanfengmao.com/logo.png', 
							    success: function () { 
							        that.text = '分享成功';
									that.flag = true;
						    		setTimeout(function() {
						    			that.flag = false;
						    		},1500)
							    },
							    cancel: function () { 
							        
							    }
							});
						});
						wx.error(function(res){
						    alert("调用失败")
						});
					},
					error: function() {

					}
				})
			},
			methods: {
				howMuch: function() {
					if(Number(this.price) > Number(this.userInfo.money)) {
						this.price = Number(this.userInfo.money).toFixed(2);
					}
				},    
				getAll: function() {
					this.price = Number(this.userInfo.money).toFixed(2);
				},
				toSend: function() {
					location.href = "{:U('red/send')}"
				},
				submit: function() { 
					var that = this;
					if(Number(this.price) < 1) {
						that.flag = true;	
						that.text = '提现金额至少一元';
						setTimeout(function() {
							that.flag = false;
						},1500)
						return false;
					}else if(Number(this.price) > 2000) {
						that.text = '提现至多2000';
						that.flag = true;	
						setTimeout(function() {
							that.flag = false;
						},1500)
						return false;
					}
					if(this.price) {
						$.ajax({    
							type: 'post',
							url: '{:U('user/withdrawApply')}',
							data: {
								id: this.userInfo.id,
								money: this.price
							},
							success: function(data) {
								if(data.code == 200) {
									that.text = '提现成功';
									that.flag = true;	
									setTimeout(function() {
										that.flag = false;
										location.href = location.href;
									},800)
								}else {
									that.text = data.msg;
									that.flag = true;	
									setTimeout(function() {
										that.flag = false;
									},800)
								}
							},
							error: function(){

							}
						})
					}
				} 
			},
			filters:{
			    toFixed:function (totalMoney) {
			      return Number(totalMoney).toFixed(2);
			    },
			}
		})
	</script>
</body>
</html>